package templator

import (
	"os"
	"text/template"
)

type FormBuilder struct {
}

func NewFormBuilder() *FormBuilder {
	return &FormBuilder{}
}

func (f *FormBuilder) FormMake() {
	tmpl, err := template.ParseFiles("form_component.tmpl")
	if err != nil {
		panic(err)
	}

	// 表单数据示例
	formData := FormData{
		Fields: []struct {
			Prop  string
			Label string
		}{
			{Prop: "username", Label: "用户名"},
			{Prop: "password", Label: "密码"},
		},
	}
	formFile, err := os.Create("FormComponent.vue")
	if err != nil {
		panic(err)
	}
	defer formFile.Close()
	err = tmpl.ExecuteTemplate(formFile, "form.tmpl", formData)
	if err != nil {
		panic(err)
	}
}

// 放置到指定路径
func (f *FormBuilder) LocationPath(path string) error {
	return nil
}
